package com.sky.dto;

import com.sky.entity.SetmealDish;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SetmealDTO implements Serializable {

    //添加组
    public interface Save{}
    //修改组
    public interface Update{}


    @Null(groups = Save.class, message = "id不能有值")//groups可以理解为作用位置
    @NotNull(groups = Update.class, message = "id不能为空")
    private Long id;

    //分类id
    @NotNull(groups = {Save.class,Update.class},message = "分类id不能为空")
    private Long categoryId;

    //套餐名称
    @Length(min = 2, max = 20, groups = {Save.class,Update.class},message = "套餐名称请输入2-20个字符")
    private String name;

    //套餐价格
    @Range(min = 0, max = 9999, groups = {Save.class,Update.class},message = "菜品价格保持在0-9999之间")
    @Digits(integer = 4, fraction = 2, groups = {Save.class,Update.class},message = "菜品价格保留4位整数,2位小数")
    private BigDecimal price;

    //状态 0:停用 1:启用
    @Range(min = 0, max = 1,groups = {Save.class,Update.class},message = "范围不在0~1之间")
    private Integer status;

    //描述信息
    private String description;

    //图片
    @URL(groups = {Save.class,Update.class},message = "图片地址不是一个正常的url")
    private String image;

    //套餐菜品关系
    @NotEmpty(groups = {Save.class,Update.class},message = "套餐下没有任何菜品")
    private List<SetmealDish> setmealDishes = new ArrayList<>();
}